package com.lizx.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lizx.admin.service.AdminAreaService;
import com.lizx.pojo.TbArea;
import com.lizx.pojo.TbProject;
import com.lizx.pojo.vo.TbAreaVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("admin/area")
public class AdminAreaController {

    @Resource
    AdminAreaService areaService;

    /**
     * 进入列表页面
     * @return
     */
    @RequestMapping("list")
    public String list(){
        return "admin/area/list";
    }

    /**
     * 获取列表数据
     * @return
     */
    @RequestMapping("getList")
    @ResponseBody
    public List<TbArea> getList(){
        return areaService.list();
    }

    @RequestMapping("selectListAll")
    @ResponseBody
    public List<TbAreaVo> selectListAll(){
        return areaService.selectListAll();
    }

    /**
     * 区域添加或修改
     * @param area
     */
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public void add(@RequestBody TbArea area){
        areaService.saveOrUpdate(area);
    }

    /**
     * 区域回显
     * @param id
     * @return
     */
    @RequestMapping("findById/{id}")
    @ResponseBody
    public TbArea findById(@PathVariable int id){
        return areaService.getById(id);
    }

    /**
     * 根据id删除
     * @param id
     */
    @RequestMapping("deleteById/{id}")
    @ResponseBody
    public void deleteById(@PathVariable int id){
        areaService.removeById(id);
    }

    /**
     * 更新状态
     * @param id
     */
    @RequestMapping("updateStatus/{id}/{status}")
    @ResponseBody
    public void updateStatus(@PathVariable int id,@PathVariable String status){
        LambdaQueryWrapper<TbArea> queryWarpper = new LambdaQueryWrapper<TbArea>();
        queryWarpper.eq(TbArea::getId,id);
        TbArea area = new TbArea();
        area.setStatus(status);
        areaService.update(area,queryWarpper);
    }

}
